// pages/my/read_record/readRecord.js
import { 
  READ_RECORD
 } from "../../../request/api";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    listData: {
      height: 0,
      loadStatus: 2,
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var windowHeight = wx.getSystemInfoSync().windowHeight;
    this.setData({
      listData: {
        height: windowHeight,
      },
    });
    this.loadMore();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  toDetail: function(e){
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    var url = type == 1? '/pages/project/detail/detail?id='+id+'&type='+type : '/pages/article/detail/detail?id='+id+'&type='+type;
    wx.navigateTo({
      url: url,
    });
  },

  refresh: function(){
    this.data.dataList = [];
    this.loadMore();
  },

  loadMore: function(){
    READ_RECORD().then(res => {
      if(res.data.code == 1){
        var temp = res.data.result;
        this.setData({
          dataList: temp,
          listData: {
            loadStatus: 3,//接口一次全部返回了
          },
        });
      } else {
      this.setLoadStatus(0);
      }
    }).catch(err => {
      this.setLoadStatus(0);
    });
  },

  setLoadStatus: function(status){
    this.setData({
      listData: {
        loadStatus: status,
      },
    });
  },
})